function [ ] = cdisp( char )
%CDISP Display a character sheet
%   IN: character structure
%    
%   Detailed, and formatted display of given character structe

% Display the name and the classes
disp(['    ' char.name '   ' char.class]);

% Display HP, AC, speed, base attack bonus,  and size bonus
hp = brpair(char.hp);
ac = int2str(char.ac);
speed = int2str(char.speed);
% break the size bonus matrix to string (e.g. [3 2 2] to 3/2/2 
bab = int2str(char.bab(1));
if size(char.bab,2) > 1
    for i = 2 : size(char.bab,2)
        bab = [bab '/' int2str(char.bab(i))];
    end
end
sb = int2str(char.size);
disp(['    HP: ' hp '    AC:' ac '    Speed:' speed]);
disp(['    Base attack bonus:' bab '    Size:' sb]);

% Display atributes
str = brpair(char.atr.str); 
dex = brpair(char.atr.dex); 
con = brpair(char.atr.con); 
int = brpair(char.atr.int); 
wis = brpair(char.atr.wis); 
cha = brpair(char.atr.cha); 
disp(['    ' 'STR:' str ' DEX:' dex ' CON:' con ' INT:' int ' WIS:' wis ' CHA:' cha]);

% Display Saving throws
fort = brpair(char.st.for); 
ref = brpair(char.st.ref); 
wil = brpair(char.st.wil); 
disp(['    ' 'Fortitude:' fort ' Reflex:' ref ' Will:' wil ]);

% Display the rest of sheet
disp('    Weapon:');
disp(brtext(char.weap));
disp('    Armor:');
disp(brtext(char.arm));
disp('    Feat:');
disp(brtext(char.feat));
disp('    Skill:');
disp(brtext(char.skil));
disp('    Bonus:');
disp(brtext(char.bonus));
disp('    Buff:');
disp(brtext(char.buf));

%%%%%%%% 
function s = brtext(text,ws)
% Break a long (>70 char) text to lines
% IN:   text - text to break
%       ws - characters (e.g. white spaces) to insert before lines
if nargin == 1
    ws = '     ';
end;
s = ws;
% Break from the begin of text to ',' character, until it is necessary
while(length(text) > 70)
    for i = 70 : -1 : 1
        if(text(i) == ',')
            s = [s text(1:i) char(10) ws];
            text = text(i + 2:length(text));
            break;
        end
    end
end
s = [s text];

function s = brpair(p)
% Break the given int pair [0 0] to string 0/0
s = [int2str(p(1)) '/' int2str(p(2))];
